package com.landun.market.web.domain;

import com.landun.market.util.NumberUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author jiang.chuan
 * @date 2018-05-05
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Pagination {
    private Integer totalRow;  // 数据量
    private Integer pageSize;  // 每页最多显示多少条数据
    private Integer pageIndex; // 当前页码
    private Integer pageCount; // 总页数

    @Builder
    public Pagination(Integer totalRow, Integer pageSize, Integer pageIndex) {
        this.totalRow = totalRow;
        this.pageSize = pageSize;
        this.pageIndex = pageIndex;
        if (NumberUtils.isPositive(totalRow) && NumberUtils.isPositive(pageSize)) {
            this.pageCount = (int) (Math.ceil(1.0 * totalRow / pageSize));
        }
    }
}
